# $Id: PKGBUILD 81888 2013-01-03 05:18:11Z fyan $
# Maintainer: Felix Yan <felixonmars@gmail.com>
# Contributor: Thomas Dziedzic < gostrc at gmail >

pkgname=sunpinyin
pkgver=2.0.3.20130103
_commit=baf4da89ac04c3eb6ea3b8fb1a10f13bf23f3d87
pkgrel=1
arch=('i686' 'x86_64')
pkgdesc="Statistical Language Model based pinyin IME by Sun"
license=('LGPL')
url="http://sunpinyin.googlecode.com"
depends=('sqlite' 'make' 'gcc-libs')
optdepends=('sunpinyin-data: Statistical language model data from open-gram project for sunpinyin')
makedepends=('git' 'scons' 'intltool')

__gitroot=git://github.com/sunpinyin/sunpinyin.git
__gitname=$pkgname

build() {
  cd "$srcdir"
  msg "Connecting to GIT server...."

  if [ -d $__gitname ] ; then
    cd $__gitname && git pull origin
    msg "The local files are updated."
  else
    git clone $__gitroot
  fi

  msg "GIT checkout done or server timeout"
  msg "Starting make..."

  rm -rf "$srcdir/$__gitname-build"
  git clone "$srcdir/$__gitname" "$srcdir/$__gitname-build"
  cd "$srcdir/$__gitname-build"
  git checkout "$_commit"

  sed -i -e "1s|python|python2|" python/*.py python/importer/*.py

  scons \
    --prefix=/usr
}

package() {
  cd "$srcdir/$__gitname-build"

  scons \
    --prefix=/usr \
    --install-sandbox="$pkgdir" \
    install
}

